﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
namespace DAO
{
    public class Register_mailDAO
    {
        static DataClasses1DataContext Data = new DataClasses1DataContext();

        public static List<REGISTER_MAIL> GetAllRegister_mail()
        {
            try
            {
                var query = from register in Data.REGISTER_MAILs select register;
                List<REGISTER_MAIL> ListRegisterMail = new List<REGISTER_MAIL>();
                foreach (REGISTER_MAIL re in query)
                {
                    ListRegisterMail.Add(re);
                }
                return ListRegisterMail;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool insertMail(REGISTER_MAIL mMail)
        {
            try
            {
                Data.REGISTER_MAILs.InsertOnSubmit(mMail);
                Data.SubmitChanges();
                return true;
            }
            catch(Exception ex)
            {
                return false;
            }
        }

        public static bool IsExisting(string mail)
        {
            return Data.REGISTER_MAILs.Any(mem => mem.EMAIL.Trim() == mail);
        }
    }
}
